package com.lsh.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/8/27 5:05 下午
 * @desc ：
 */
//@Component
@Slf4j
public class RabbitMQConsumer2 {

    @RabbitListener(queues = "deadLetterQueueA")
    public void receiveA(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},死信队列A收到消息：{}", new Date().toString(), msg);
        System.out.println("现在时间是："+ LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)+"  消费者A："+msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
//    @RabbitHandler
    @RabbitListener(queues = "hw_data")
    public void receive2(Message message, Channel channel) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{},死信队列A收到消息：{}", new Date().toString(), msg);
        System.out.println("消费者A："+msg);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
